/**
 * Created by Administrator on 2016/5/19.
 */

/*******************************************************************************
 * 功能：公共方法和基础数据
 * 作者：jame
 * 时间：2016-05-24 04:13
 ******************************************************************************/
var publicMethods = {
    pathSetting : {
        environment: 'onehome.me',  //网站域名
        picture_host: 'cachezero.ciker360.com',  //图片引用路径
        picture_post: 'cachezero.ciker360.com/put.php',  //图片引用路径
        userHeadUrl: '/images/user_pic-225x225.png',  //默认的用户头像图片
        hosueImgUrl: '/images/pic_default_image.png'  //默认的房源图片
    },
    //设置货币代号
    setBuyerCurrency: function (b) {
        $.cookie("buyer_currency", b, {expires: 10, path: '/'});
    },
    //获取货币代号
    getBuyerCurrency: function() {
        var buyerCurrency = $.cookie("buyer_currency") ? $.cookie("buyer_currency") : '1';;
        if(buyerCurrency == 0){
            $.cookie("buyer_currency", 1, {expires: 10, path: '/'});
            buyerCurrency = 1;
        }
        return buyerCurrency;
    },
    //设置货币符号
    setCurrencySymbol: function(s) {
        $.cookie("currency_symbol", s, {expires: 10, path: '/'});
    },
    //获取货币符号
    getCurrencySymbol: function() {
        return $.cookie("currency_symbol") ? $.cookie("currency_symbol") : setting.rmb;
    },
    // 获取货币简写
    getCurrencyType: function () {
        var currency_type = '';
        if($.cookie('currency_symbol_arr')){
            var currency_symbol_arr = JSON.parse($.cookie('currency_symbol_arr'));
            currency_type = currency_symbol_arr[parseInt(this.getBuyerCurrency())-1].type;
        }
        return currency_type;
    },
    //用户头像路径
    getUserHeadUrl: function(pn, size) {
        if(!size){
            size = 'large';
        }
        if (!pn) {
            return this.pathSetting.userHeadUrl;
        } else {
            return '//' + this.pathSetting.picture_host + '/get.php?pn=' + pn + '&pt=0&st=' + size;
        }
    },
    //获取房源图片路径 url(图片的原始路径) size(图片的大小) quality(图片的质量) type(true的情况下显示最新的图片路径)
    getHouseUrl: function(url, size ,quality, type) {
        if(!size){
            size = 'large';
        }
        //type为true的情况下显示最新的头路径
        if(type){
            if(quality){
                quality = '&quality='+quality;
            }else{
                quality = '';
            }
            return url + '?pt=1&st=' + size + quality;
        }else{
            if(quality){
                quality = '_'+quality;
            }else{
                quality = '';
            }
            url = url.substring(0, url.length-4);
            url = url.replace('pictures', 'p');
            return url+'_1_'+ size + quality + '.jpg';
        }
    },
    //货币

    moneyArr:[
        {
            "type": "CNY",
            "symbol": "￥",
            "name": "CNY",
            "typeNum": "1",
            "rate": "1"
        },
        {
            "type": "USD",
            "symbol": "$",
            "name": "USD",
            "typeNum": "2",
            "rate": "6.3622"
        },
        {
            "type": "TWD",
            "symbol": "$",
            "name": "TWD",
            "typeNum": "3",
            "rate": "0.203"
        },
        {
            "type": "THB",
            "symbol": "฿",
            "name": "THB",
            "typeNum": "4",
            "rate": "0.1855"
        },
        {
            "type": "JPY",
            "symbol": "￥",
            "name": "JPY",
            "typeNum": "5",
            "rate": "0.052711"
        },
        {
            "type": "KRW",
            "symbol": "₩",
            "name": "KRW",
            "typeNum": "6",
            "rate": "0.005847"
        },
        {
            "type": "EUR",
            "symbol": "€",
            "name": "EUR",
            "typeNum": "7",
            "rate": "7.0379"
        },
        {
            "type": "CAD",
            "symbol": "$",
            "name": "CAD",
            "typeNum": "8",
            "rate": "4.8316"
        },
        {
            "type": "AUD",
            "symbol": "$",
            "name": "AUD",
            "typeNum": "9",
            "rate": "4.6003"
        },
        {
            "type": "GBP",
            "symbol": "£",
            "name": "GBP",
            "typeNum": "10",
            "rate": "9.7755"
        },
        {
            "type": "HKD",
            "symbol": "$",
            "name": "HKD",
            "typeNum": "11",
            "rate": "0.8208"
        },
        {
            "type": "SGD",
            "symbol": "$",
            "name": "SGD",
            "typeNum": "12",
            "rate": "4.5678"
        },
        {
            "type":"MYR",
            "symbol":"M",
            "name":"MYR",
            "typeNum":"13",
            "rate":"1.5497"
        }
    ],
    getSymbolByNum:function(num){
        var symbol='￥';
        for(var i=0;i<publicMethods.moneyArr.length;i++)
        {
            if(publicMethods.moneyArr[i].typeNum==num)
            {
                symbol=publicMethods.moneyArr[i].symbol;
                break;
            }
        }
        return symbol;
    },
    getRoomType: function (num) {
        num = parseInt(num);
	    var roomType = [$.i18n.prop('171233d86cf4b71268ec4b8048f69a20'),$.i18n.prop('82cf9d8d68b82584ecc68bf4fed0639c'),$.i18n.prop('77f5873a3ae1bfa3c4f5e049e6a01d71'),$.i18n.prop('7219ffbfc3b2b4f91bf627237a771ac7')];
        return roomType[num];
    },
    getHouseStatus: function (houseStatus) {
	    houseStatus = parseInt(houseStatus);
	    var houseStatusArr = [$.i18n.prop('171233d86cf4b71268ec4b8048f69a20'),$.i18n.prop('718136507c1800cb4f1e47256fb968dc'),$.i18n.prop('922dabcf831e07d70a3f9b0298f8e3d4'),$.i18n.prop('1873f8f90db514cb9bfb534e9c634f91'),$.i18n.prop('a3d111fc52b3d3afdfcda88d9e84eec0'),$.i18n.prop('5b4b1ea7eee1a145c04ee0f3ccf92ad5'),$.i18n.prop('a065491bcce6624558c29f73fc76744c')];
	    return houseStatusArr[houseStatus];
    },

    languageArr: {
	    "zh":"ba61401f60eaab451e8cd2e739aa7a03",
	    "tw":"ba61401f60eaab451e8cd2e739aa7a04",
	    "en":"ba61401f60eaab451e8cd2e739aa7a05",
	    "ja-jp":"ba61401f60eaab451e8cd2e739aa7a06",
	    "ko-kr":"ba61401f60eaab451e8cd2e739aa7a07"
    }
}



$(function(){
    $('.noleftborder').on({ //仿input获取焦点效果
        'click':function(){$(this).parents('.inputgroup').addClass('active');},
        'blur':function(){$(this).parents('.inputgroup').removeClass('active');}
    })

    //移入按钮时改变按钮颜色
    $('.btn.btn-primary.btnfocus').hover(function(){
            $(this).css('background-color','#ff7877');
        },
        function(){
            $(this).css('background-color','#ff5a5f');
        }
    )

    /*
     * 点击页面，让弹出的国家选择隐藏
     * for (登录、注册、找回密码)templates\onehome\html\login\login.html
     */
    $(document).click(function(){
	    $('.prefixPhoneNum_box').hide();
        if($('.houseType_box').css('display') == 'block'){
            $('.houseType_box').hide();
        }
    });
    /*
     * 点击国家选择框，展示出国家选择长条
     * for (登录、注册、找回密码) templates\onehome\html\login\login.html
     */
    $(document).on('click','input[name=prefixPhoneNums]',function(e){
        e.stopPropagation();
        if($(this).siblings('.prefixPhoneNum_box').css('display') == 'none'){
	        $(this).siblings('.prefixPhoneNum_box').show();
        }else{
	        $(this).siblings('.prefixPhoneNum_box').hide();
        }
    });
    /*
     * 点击某个国家，给输入框设置国家的代码
     * for (登录、注册、找回密码) templates\onehome\html\login\login.html
     */
    $(document).on('click','.prefixPhoneNum_box .prefixNum',function(){
        num = $(this).attr('data-num');
        num2= num.replace("00","+");
        $(this).parents('.prefix').find('input[name=prefixPhoneNum]').attr('value',num);
	    $(this).parents('.prefix').find('input[name=prefixPhoneNums]').attr('value',num2);
    });

    //防止代码注入
    injectShield();

    addLisenerForHeader();//头部监听

    //房源模块中收藏按钮
	$('body').on('click','.collectionIcon',function () {
		var yyoh = $.cookie('yyoh');
		var userId = $.cookie('id');
		if(!yyoh || !userId){
			var history = window.location.pathname+window.location.search;
			history = history.length?('?history='+history):'';
			window.location.href="/login/p_login"+history;
			return false;
		}
		var that = $(this);
		var houseid = $(this).attr('data-id');
		var isCollect = $(this).attr('data-isCollect');
		var port = isCollect=='1'?'collect/cancelCollect':'collect/addCollect';
		var param = {
			yyoh: yyoh,
			userId: userId,
			houseId: houseid
		};
		var value = JSON.stringify(param);
		treatData(port,value,function(data){
			if(data.status.status_code == 0){
				that.attr('data-isCollect',isCollect=='1'?'0':'1');
				that.attr('src',isCollect=='1'?'/images/search/collection.png':'/images/search/collection_red.png')
			}else{
				alert(data.status.status_reason);
			}
		});
		return false;
	})
});


/*
 *验证(从basse上复制)
 * **/
var verification={
    empty:function(str){
        var result = {};
        if(str == ''){
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('eca550675cee367d765227adc616487a');
        }else{
            result.status_code = '0';
            result.status_reason = $.i18n.prop('ef2ce13fa733adfadcdf3bfc59e83d97');
        }
        return result;
    },
    money:function(str) {
        var result = {};
        var idReg=/^[0-9][0-9]*$/;
        if(str == ''){
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('18aff131ec9293370e8ab36701e83f3f');
            return result;
        }else if(str<0){
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('5b1cd0362d79a4e7ccafd5e6397224a9');
            return result;
        }else if(!idReg.test(str)){
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('2680143b0761c4526b6cc01832499ba6');
        }else{
            result.status_code = '0';
            result.status_reason = $.i18n.prop('ef2ce13fa733adfadcdf3bfc59e83d97');
        }
        return result;
    },
    password:function(str) {
        var result = {};
        if(/.*[\u4e00-\u9fa5]+.*$/.test(str)){
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('dd3775f93f76797150f6a7f30369cc4c');
        }else if(str.length < 6 || str.length > 20){
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('223971c488a11ee68b339ecea0d9f809');
        }else{
            result.status_code = '0';
            result.status_reason = $.i18n.prop('ef2ce13fa733adfadcdf3bfc59e83d97');
        }
        return result;
    },
    passwordConfirm:function(str,str2) {
        var result = {};
        if(str != str2){
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('89cd05af1bb3f410f5a381bebea154dd');
        }else{
            result.status_code = '0';
            result.status_reason = $.i18n.prop('ef2ce13fa733adfadcdf3bfc59e83d97');
        }
        return result;
    },
    email:function(str) {
        var result = {};
        if (str.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('a64a8249f0ce4f2f5e0656c0e0de5ca9');
        }else{
            result.status_code = '0';
            result.status_reason = $.i18n.prop('ef2ce13fa733adfadcdf3bfc59e83d97');
        }
        return result;
    },
    character:function(str,min,max) {
        var result = {};
        if(str.length < min || str.length > max){
            result.status_code = '-1';
            if(str.length < min){
                result.status_reason = $.i18n.prop('e2c48ace7d7425d647ea3e64df45dbec')+min+$.i18n.prop('f225f3e58556594cb03a4d38d3c3261d');
            }else{
                result.status_reason = $.i18n.prop('fb054924aeed3f8fe9a7d28f80bb7b3b')+max+$.i18n.prop('c5102d6628adb14b87df9e32aa7d09b3');
            }
        }else{
            result.status_code = '0';
            result.status_reason = $.i18n.prop('ef2ce13fa733adfadcdf3bfc59e83d97');
        }
        return result;
    },
    phone:function(phone) {
        console.log('aaaa' + phone)
        var result = {};
        // var a = /^((\(\d{3}\))|(\d{3}\-))?13\d{9}|14[57]\d{8}|15\d{9}|18\d{9}$/ ;
        var a = /^1\d{10}$/;
        if(!phone.length){
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('d932847925fdc6d871b21ff0696f306d');
        }else if( phone.length!=11 || !phone.match(a)) {
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('b1d155498b65d4d4ebac94f6f4d9925b');
        }else{
            result.status_code = '0';
            result.status_reason = $.i18n.prop('ef2ce13fa733adfadcdf3bfc59e83d97');
        }
        return result;
    },
    isPInt:function(str,min) {
        var result = {};
        var a = /^[1-9]*[1-9][0-9]*$/;
        var re = new RegExp(a);
        if(!str.match(re)) {
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('decd3562e3e92664e025ed97d540208e');
        }else if(str >= min){
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('56be149a9c8e1d102a3e3823dacb18e0')+min;
        }else{
            result.status_code = '0';
            result.status_reason = $.i18n.prop('ef2ce13fa733adfadcdf3bfc59e83d97');
        }
        return result;
    },
    isNumber:function(str){ //数字
        var result = {};
        var a = /^[0-9]*$/;
        var re = new RegExp(a);
        if(!str.match(re)) {
            result.status_code = '-1';
            result.status_reason = $.i18n.prop('f9829791f84358d6de53d0670598ad4f');
        }else{
            result.status_code = '0';
            result.status_reason = $.i18n.prop('ef2ce13fa733adfadcdf3bfc59e83d97');
        }
        return result;
    }
}

//验证是否登录（从base上复制）
function verifyLogin(){
    if($.cookie('yyoh') && $.cookie('id')){
        window.location.replace("/");
    }
}

/*******************************************************************************
 * 功能：根据页面路径动态设定导航的选中状态
 * 作者：jame
 * 时间：2016-05-24 04:13
 ******************************************************************************/
function setNavForUserInfo(){
    var pathname = window.location.pathname;
    var start = pathname.indexOf('_');
    var start = start + 1;
    var path = pathname.substring(start);
    $('.nav-details').children('li').children('a').each(function(i){
        var navl = $(this).attr('data-nav');
        if(navl.indexOf(path)>=0){
            $(this).parent().addClass('action');
        }
    });
}

/*******************************************************************************
 * 功能：个人中心当行菜单点击切换事件
 * 参数：fn(回调事件)
 * 作者：jame
 * 时间：2016-05-24 04:13
 ******************************************************************************/
function clickNavTabForUserInfo(fn){
    //点击事件
    $('.userInfo .topNav .menu').click(function(){
        //获取当前红色按钮的位置
        var prev = parseInt($('.userInfo .topNav .menu.active').index())/2;
        //获取要点击的红色按钮的位置
        var index = parseInt($(this).index())/2;
        //切换按钮的颜色
        $('.userInfo .topNav .menu').removeClass('active');
        $(this).addClass('active');
        //显示隐藏相应的页面
        $('.topNav'+index).siblings().hide();
        $('.topNav'+index).show();
        //函数回调
        if(fn){
            fn(index);
        }
    });
}

/*******************************************************************************
 * 功能：获取分页数据
 * 参数：page(当前页) pageSize(每页个数) total(总个数) postfix(回调函数)
 * 作者：jame
 * 时间：2016-05-24 07:19
 ******************************************************************************/
function setPageForSearch(page,pageSize,total,postfix){
    var  pageCount = Math.ceil(total/pageSize);
    var str = "";
    if(page>1){
        str = str + '<li class="prev previous_page"><a rel="prev" href="javascript:void(0)" onclick="previous_page_'+postfix+ '()"><span class="screen-reader-only">' + $.i18n.prop('13110543711ca7be5e65ee83ffeb0874') + '</span><i class="icon icon-caret-left"></i></a></li> ';
    }
    if(pageCount <= 7){

        for(var i=1;i<=pageCount;i++){
            if(i==page){
                str = str + '<li class="active"><a rel="next" href="javascript:void(0)">'+i+'</a></li>';
            }else{
                str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+i+')" href="javascript:void(0)">'+i+'</a></li>';
            }
        }

    }else{
        if(page<3){
            if(page == 1){
                str = str + '<li class="active"><a rel="next" href="javascript:void(0)">1</a></li>';
                str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(2)" href="javascript:void(0)">2</a></li>';
                str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(3)" href="javascript:void(0)">3</a></li>';
            }else{
                str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(1)" href="javascript:void(0)">1</a></li>';
                str = str + '<li class="active"><a rel="next" href="javascript:void(0)">2</a></li>';
                str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(3)" href="javascript:void(0)">3</a></li>';
            }
            str = str + '<li class="gap"><span class="gap">…</span></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+pageCount+')" href="javascript:void(0)">'+pageCount+'</a></li>';
        }else if(page == 3){
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(1)" href="javascript:void(0)">1</a></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(2)" href="javascript:void(0)">2</a></li>';
            str = str + '<li class="active"><a rel="next" href="javascript:void(0)">3</a></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(4)" href="javascript:void(0)">4</a></li>';
            str = str + '<li class="gap"><span class="gap">…</span></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+pageCount+')" href="javascript:void(0)">'+pageCount+'</a></li>';
        }else if(page == 4){
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(1)" href="javascript:void(0)">1</a></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(2)" href="javascript:void(0)">2</a></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(3)" href="javascript:void(0)">3</a></li>';
            str = str + '<li class="active"><a rel="next" href="javascript:void(0)">4</a></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(5)" href="javascript:void(0)">5</a></li>';
            str = str + '<li class="gap"><span class="gap">…</span></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+pageCount+')" href="javascript:void(0)">'+pageCount+'</a></li>';
        }else if(page > 4 && page < parseInt(pageCount)-3){
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(1)" href="javascript:void(0)">1</a></li>';
            str = str + '<li class="gap"><span class="gap">…</span></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+(parseInt(page)-1)+')" href="javascript:void(0)">'+(parseInt(page)-1)+'</a></li>';
            str = str + '<li class="active"><a rel="next" href="javascript:void(0)">'+page+'</a></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+(parseInt(page)+1)+')" href="javascript:void(0)">'+(parseInt(page)+1)+'</a></li>';
            str = str + '<li class="gap"><span class="gap">…</span></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+pageCount+')" href="javascript:void(0)">'+pageCount+'</a></li>';
        }else if(page == parseInt(pageCount)-3){
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(1)" href="javascript:void(0)">1</a></li>';
            str = str + '<li class="gap"><span class="gap">…</span></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+(parseInt(pageCount)-4)+')" href="javascript:void(0)">'+(parseInt(pageCount)-4)+'</a></li>';
            str = str + '<li class="active"><a rel="next" href="javascript:void(0)">'+(parseInt(pageCount)-3)+'</a></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+(parseInt(pageCount)-2)+')" href="javascript:void(0)">'+(parseInt(pageCount)-2)+'</a></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+(parseInt(pageCount)-1)+')" href="javascript:void(0)">'+(parseInt(pageCount)-1)+'</a></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+pageCount+')" href="javascript:void(0)">'+pageCount+'</a></li>';
        }else if(page == parseInt(pageCount)-2){
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(1)" href="javascript:void(0)">1</a></li>';
            str = str + '<li class="gap"><span class="gap">…</span></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+(parseInt(pageCount)-3)+')" href="javascript:void(0)">'+(parseInt(pageCount)-3)+'</a></li>';
            str = str + '<li class="active"><a rel="next" href="javascript:void(0)">'+(parseInt(pageCount)-2)+'</a></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+(parseInt(pageCount)-1)+')" href="javascript:void(0)">'+(parseInt(pageCount)-1)+'</a></li>';
            str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+pageCount+')" href="javascript:void(0)">'+pageCount+'</a></li>';
        }else if(page > parseInt(pageCount)-2){
            if(page == parseInt(pageCount)-1){
                str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(1)" href="javascript:void(0)">1</a></li>';
                str = str + '<li class="gap"><span class="gap">…</span></li>';
                str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+(parseInt(pageCount)-2)+')" href="javascript:void(0)">'+(parseInt(pageCount)-2)+'</a></li>';
                str = str + '<li class="active"><a rel="next" href="javascript:void(0)">'+(parseInt(pageCount)-1)+'</a></li>';
                str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+pageCount+')" href="javascript:void(0)">'+pageCount+'</a></li>';
            }else{
                str = str + '<li><a rel="next" onclick="this_page_'+postfix+'(1)" href="javascript:void(0)">1</a></li>';
                str = str + '<li class="gap"><span class="gap">…</span></li>';
                str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+(parseInt(pageCount)-2)+')" href="javascript:void(0)">'+(parseInt(pageCount)-2)+'</a></li>';
                str = str + '<li><a rel="next" onclick="this_page_'+postfix+'('+(parseInt(pageCount)-1)+')" href="javascript:void(0)">'+(parseInt(pageCount)-1)+'</a></li>';
                str = str + '<li class="active"><a rel="next" href="javascript:void(0)">'+pageCount+'</a></li>';
            }
        }
    }
    if(page<pageCount){
        str = str + '<li class="next next_page"><a rel="next" href="javascript:void(0);" onclick="next_page_'+postfix+ '()"><span class="screen-reader-only">' + $.i18n.prop('2ba81979e1fc48c7d34fd2ff87e24ed7') + '</span><i class="icon icon-caret-right"></i></a></li>';
    }
    return str;
}



/*******************************************************************************
 * 功能：去掉空格
 * 用法：str.trim()
 * 作者：jame
 * 时间：2016-05-25 16:40
 ******************************************************************************/
String.prototype.trim = function() {
    //return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    return $.trim(this);
}

/*******************************************************************************
 * 功能：登录操作(从base上复制)
 * 作者：jiph
 * 时间：2016-05-26 12:24
 ******************************************************************************/
function loginLink(){
    var host = window.location.host;
    var href = window.location.href;
    var his_ex = href.indexOf(host);
    var history = href.substring(his_ex+host.length,href.length);
    if(history.indexOf('/forget/p_forget')>=0 || history.indexOf('/login/p_login') >= 0 || history.indexOf('/register/p_register') >= 0){
        window.location.href='/login/p_login';
    }else{
        window.location.href='/login/p_login?history='+history;
    }
}

/*******************************************************************************
 * 功能：忘记密码的时间获取验证码 (从base上复制)
 * 作者：jiph
 * 时间：2016-05-26 12:24
 ******************************************************************************/
function getVerificationForForgetPhone(){
    $('.back_infor').html('');
    var boo = true;
    var phone = $("input[name='phone']").val().trim();
    var phoneresult=verification.isNumber(phone);
    if(phoneresult.status_code!=0 ||!phone){
        $('.back_infor_user').html($.i18n.prop('17cd1e4870ed565753713b5d85d8f035'));
        boo = false;
    };
    var imgVeriCode = $("input[name='imgVeriCode']").val();
    if(imgVeriCode.length != 4){
        $('.back_infor_img').html($.i18n.prop('f9e319178e10ab756031ac0b6d024f4d'));
        boo = false;
    }
    if(boo){
        $('#verification').attr('disabled','disabled');
        $('.back_infor').html('');
        var myDate = new Date();
        var prefixPhoneNum = $("#prefixPhoneNum").attr('value');
        $.post("/forget/c_forgetPhone", { act:"veriCode",phone:phone,prefixPhoneNum:prefixPhoneNum,imgVeriCode:imgVeriCode,date:myDate},
            function(data){
                if(data.status_code == 0){
                    $('#verification').html($.i18n.prop('2f33f350ff503cab3fa8b65daa3742fe') + '<one></one>' + $.i18n.prop('2f33f350ff503cab3fa8b65daa3742ff'));
                    $('#verification').children('one').html('120');
                    time();
                    $('input[name=veriCode]').focus();
                }else{
                    $('#verification').removeAttr("disabled");
                    $('#infor_back').html(data.back_infor);
                    $('.alert-info').slideDown();
                    setTimeout(function(){$('.alert-info').slideUp();}, 4000);
                }
            }, "json");
    }
};

/*******************************************************************************
 * 功能：注册的时候获取验证码函数 (从base上复制)
 * 作者：jiph
 * 时间：2016-05-26 12:24
 ******************************************************************************/
function getVerificationForRegister(){

    $('.back_infor').html('');
    var boo = true;
    var phone = $("input[name='phone']").val();
    var phoneresult=verification.isNumber(phone);
    if(phoneresult.status_code!=0 ||!phone){
        $('.back_infor_user').html($.i18n.prop('17cd1e4870ed565753713b5d85d8f035'));
//                    $('input[name=phone]').addClass('border_box_red');
        boo = false;
    };
    var imgVeriCode = $("input[name='imgVeriCode']").val();
    if(imgVeriCode.length != 4){
        $('.back_infor_img').html($.i18n.prop('be004960ad27d56eba4b045c33923925'));
        boo = false;
    }
    if(boo){
        $('#verification').attr('disabled','disabled');
        var myDate = new Date();
        var prefixPhoneNum = $("#prefixPhoneNum").attr('value');
        $.post("/register/c_register2", { "act": "veriCode","phone":phone,"prefixPhoneNum":prefixPhoneNum,"imgVeriCode":imgVeriCode,"date":myDate},function(data){
            if(data.status_code == 0){
                $('#verification').html($.i18n.prop('2f33f350ff503cab3fa8b65daa3742fe') + '<one></one>' + $.i18n.prop('2f33f350ff503cab3fa8b65daa3742ff'));
                $('#verification').children('one').html('120');
                time();
            }else{
                $('#verification').removeAttr("disabled");
                $('#infor_back').html(data.back_infor);
                $('.alert-info').slideDown();
                setTimeout(function(){$('.alert-info').slideUp();}, 4000);
            }
        }, "json");
    }
}


/*******************************************************************************
 * 功能：配合获取验证码函数进行倒计时 (从base上复制)
 * 作者：jiph
 * 时间：2016-05-26 12:24
 ******************************************************************************/
var wait=120;
function time() {
    if (wait == 0) {
        $('#verification').attr('data-get','0');
        $('#verification').attr('disabled',false);
        $('#verification').html('<one></one>' + $.i18n.prop('1cb7136b36107b5fcc14b9059afa3330')).removeClass('waitbtn');
        wait = 120;
        /*if(getSendVeriCodeForPage){
            getSendVeriCodeForPage();
        }*/
    } else {
        $('#verification').attr('disabled','disabled');
        $('#verification').children('one').html(wait);
        wait--;
        setTimeout(function() {
                time();
            },
            1000);
    }
}

/*******************************************************************************
 * 功能：防止代码注入 (从base上复制)
 * 作者：jiph
 * 时间：2016-05-26 12:24
 ******************************************************************************/
function injectShield(){
    checkShield();
    setTimeout(function(){checkShield();}, 500);
    setTimeout(function(){checkShield();}, 1000);
    setTimeout(function(){checkShield();}, 2000);
    setTimeout(function(){checkShield();}, 4000);
    function checkShield(){
        if($('.__boundary').length>0){
            var next = $('.__boundary').next();
            for(var i=0;i<100;i++){
                if(next.length>0){
                    var _this = next;
                    next = next.next();
                    _this.remove();
                }else{
                    break;
                }
            }
        }
    }
}
function exit(){
    $.cookie("sid",null,{"expires":-1,path:"/"});
    $.cookie("yyoh",null,{"expires":-1,path:"/"});
    $.cookie("user_nickName",null,{"expires":-1,path:"/"});
    $.cookie("user_faceUrl",null,{"expires":-1,path:"/"});
    $.cookie("id",null,{"expires":-1,path:"/"});
    $.cookie("prefixPhoneNum",null,{"expires":-1,path:"/"});
    $.cookie("phone",null,{"expires":-1,path:"/"});
    $.cookie("password",null,{"expires":-1,path:"/"});
    $.cookie("remember_me",null,{"expires":-1,path:"/"});
    $.cookie("temporary_chat",null,{"expires":-1,path:"/"});
    $.cookie("openedchatbox",null,{"expires":-1,path:"/"});
    $.cookie("openedservicebox",null,{"expires":-1,path:"/"});


    var href = window.location.href;
    if(href.indexOf('systemParam')>=0 && href.indexOf('yyoh')>=0 && href.indexOf('userId')>=0){
        window.location.replace(window.location.protocol+'//'+window.location.host+window.location.pathname);
    }else{
        window.location.reload();
    }
}


/*******************************************************************************
 * 功能：自动登录操作 (从base上复制)
 * 作者：jiph
 * 时间：2016-05-26 12:24
 ******************************************************************************/
function autoLogin(){
    if($.cookie("remember_me") == 'true' && $.cookie("autoLogin") == '0'){
        $.cookie("autoLogin", 1,{path: '/'});//不管怎么样，自动登录只进行一次
        var myDate = new Date();
        var phone = $.cookie("phone");
        var password = $.cookie("password");
        var prefixPhoneNum = $.cookie("prefixPhoneNum");
        $.post("/login/c_login", { phone:phone,prefixPhoneNum:prefixPhoneNum,password:password,date:myDate},function(data){
            if(data.status_code == 0){
//                $.cookie("sid", data.result.sid,{path: '/'});
//                $.cookie("id", data.result.id,{path: '/'});
                //追踪路径返回页面
                var href = window.location.href;
                var loc_ex = href.indexOf('login/p_login');
                if(loc_ex>-1){
                    var his_ex = href.indexOf('history');
                    if(his_ex>-1){
                        his_ex = his_ex + 8;
                        var all_ex = href.length;
                        var history = href.substring(his_ex,all_ex);
                        var host = window.location.host;
                        window.location.replace("//"+host+history);
                    }else{
                        window.location.replace("/");
                    }
                }else{
                    window.location.reload();
                }
            }else{
                //自动登录失败的时候不进行任何操作
//                $('#infor_back').html('自动登录失败，请手动登录');
//                $('.alert-info').slideDown();
//                setTimeout(function(){$('.alert-info').slideUp();}, 4000);
            }
        }, "json");
    }
}


/*******************************************************************************
 * 功能：地址选择器
 * 作者：jame
 * 时间：2016-05-26 10:44
 ******************************************************************************/
//(function ($) {
//    $.fn.addressSelect = function(options) {
//        //定义变量信息
//        options = jQuery.extend({
//            levelName1        : '',       //默认：一级地址
//            levelName2        : '',       //默认：二级地址
//            levelName3        : '',       //默认：三级地址
//            levelName4        : '',       //默认：四级地址
//            levelId1        : '',       //默认：一级地址
//            levelId2        : '',       //默认：二级地址
//            levelId3        : '',       //默认：三级地址
//            levelId4        : '',       //默认：四级地址
//            callback          : null,     //默认：空的回调函数，返回参数(当前层级，层级的数据，总层级)
//        }, options);
//        this.opts = $.extend({}, $.fn.addressSelect.defaults, options);
//        $.fn.extend(this, addressSelect);
//        //正式的调用以及渲染
//        this.init();
//    }
//
//    var addressSelect = {
//        init:function(){
//            var _this = this;
//            //获取一级国家列表
//            getCountryList2(function(data){
//                if(data.status.status_code == 0){
//                    _this.addressDisplay(data.result.CountryList,1);
//                }
//            });
//            //添加切换监听事件
//            this.addMonitor();
//        },
//        addressDisplay:function(adAr,level){
//            if(level == 1){
//                this.children('select[name=levelId'+level+']').html('');
//                this.children('select[name=levelId'+level+']').append('<option value="0">未设置</option>');
//                //渲染国家数据
//                for(var i=0;i<adAr.length;i++){
//                    if(this.opts.levelId1 == adAr[i].id){
//                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" level="'+adAr[i].addressLevel+'" selected>'+adAr[i].name+'</option>');
//                    }else{
//                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" level="'+adAr[i].addressLevel+'">'+adAr[i].name+'</option>');
//                    }
//                }
//                if(this.opts.levelId2 != ''){
//                    this.children('select[name=levelId2]').html('<option value="'+this.opts.levelId2+'">'+this.opts.levelName2+'</option>');
//                }
//
//                if(this.opts.levelId3 != 0){
//                    this.children('select[name=levelId3]').show();
//                    this.children('select[name=levelId3]').html('<option value="'+this.opts.levelId3+'">'+this.opts.levelName3+'</option>');
//                }
//                if(this.opts.levelId4 != 0){
//                    this.children('select[name=levelId4]').show();
//                    this.children('select[name=levelId4]').html('<option value="'+this.opts.levelId4+'">'+this.opts.levelName4+'</option>');
//                }
//            }else if(level == 2){
//                this.children('select[name=levelId'+level+']').html('');
//                this.children('select[name=levelId'+level+']').append('<option>选择省</option>');
//                for(var i=0;i<adAr.length;i++){
//                    this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'">'+adAr[i].provinceName+'</option>');
//                }
//            }else if(level == 3){
//                this.children('select[name=levelId'+level+']').html('');
//                this.children('select[name=levelId'+level+']').append('<option>选择城市</option>');
//                for(var i=0;i<adAr.length;i++){
//                    this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'">'+adAr[i].cityName+'</option>');
//                }
//            }else if(level == 4){
//                this.children('select[name=levelId'+level+']').html('');
//                this.children('select[name=levelId'+level+']').append('<option>选择乡镇</option>');
//                for(var i=0;i<adAr.length;i++){
//                    this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'">'+adAr[i].districtName+'</option>');
//                }
//            }
//        },
//        addMonitor:function(){
//            var _this = this;
//            _this.children().on('change',function(){
//                //当前层级
//                var levelId = $(this).attr('name');
//                //国家的层级
//                var level = parseInt(_this.children().eq(0).find("option:selected").attr('level'));
//                //经纬度
//                var latitude = $(this).find("option:selected").attr('latitude');
//                //经纬度
//                var longitude = $(this).find("option:selected").attr('longitude');
//                //当前选择的地址的id
//                var value = $(this).find("option:selected").val();
//                //当前
//                var text = $(this).find("option:selected").text();
//                var back = {};
//                back.levels=level;
//                back.value=value;
//                back.text=text;
//                (latitude!=undefined)?(back.latitude=latitude):"";
//                (longitude!=undefined)?(back.longitude=longitude):"";
//
//                if(levelId == 'levelId1'){
//                    back.level=1;
//                    getProvinceByCountry(value,function(data){
//                        if(data.status.status_code == 0){
//                            _this.addressDisplay(data.result.ProvinceList,2);
//                        }
//                    });
//                }else if(levelId == 'levelId2'){
//                    back.level=2;
//                    //如果层级大于等于三级，就继续向下查询
//                    if(level >= 3){
//                        getCityByProvince(value,function(data){
//                            if(data.status.status_code == 0){
//                                _this.addressDisplay(data.result.CityList,3);
//                            }
//                        });
//                    }
//                }else if(levelId == 'levelId3'){
//                    back.level=3;
//                    //如果层级大于等于三级，就继续向下查询
//                    if(level == 4){
//                        getDistrictByCity(value,function(data){
//                            if(data.status.status_code == 0){
//                                _this.addressDisplay(data.result.DistrictList,4);
//                            }
//                        });
//                    }
//                }else{
//                    back.level=4;
//                }
//                //回调函数
//                if(_this.opts.callback){
//                    _this.opts.callback(back);
//                }
//                //根据当前国家的层级显隐相应的选择框
//                if(level == 2){
//                    _this.children('select[name=levelId3]').hide();
//                    _this.children('select[name=levelId4]').hide();
//                }else if(level == 3){
//                    _this.children('select[name=levelId3]').show();
//                    _this.children('select[name=levelId4]').hide();
//                }else if(level == 4){
//                    _this.children('select[name=levelId3]').show();
//                    _this.children('select[name=levelId4]').show();
//                }
//            });
//        }
//    }
//})(jQuery);

/*******************************************************************************
 * 功能：地址选择器
 * 作者：jame
 * 时间：2016-06-3 16:44
 ******************************************************************************/
(function ($) {
    $.fn.addressSelect = function(options) {
        //定义变量信息
        options = jQuery.extend({
            levelName1        : '',       //默认：一级地址
            levelName2        : '',       //默认：二级地址
            levelName3        : '',       //默认：三级地址
            levelName4        : '',       //默认：四级地址
            levelId1        : '',       //默认：一级地址
            levelId2        : '',       //默认：二级地址
            levelId3        : '',       //默认：三级地址
            levelId4        : '',       //默认：四级地址
            callback          : null,     //默认：空的回调函数，返回参数(当前层级，层级的数据，总层级)
            oneCallback       : null,      //默认：空的回调函数，返回参数(当前层级，层级的数据，总层级) 插件初次渲染回调函数,也是每次渲染后回调函数
            realOneCallback       : null,      //暂无实现,无调用.默认：空的回调函数.真正只调用一次的callback
        }, options);
        this.opts = $.extend({}, $.fn.addressSelect.defaults, options);
        $.fn.extend(this, addressSelect);
        //正式的调用以及渲染
        this.init();
    }

    var addressSelect = {
        init:function(){
            var _this = this;
            //获取一级国家列表
            getCountryList2(function(data){
                if(data.status.status_code == 0){
                    _this.addressDisplay(data.result.CountryList,1);
                }
            });
            //添加切换监听事件
            this.addMonitor();
        },
        addressDisplay:function(adAr,level,changeFor){
            var _this = this;
            if(level == 1){
                this.children('select[name=levelId'+level+']').html('');
                if(this.opts.levelId1 > 0){
                    this.children('select[name=levelId'+level+']').append('<option value="0" level="2" disabled>' + $.i18n.prop('0d3dcd210e07c8042720af18d1a8da96') + '</option>');
                }else{
                    this.children('select[name=levelId'+level+']').append('<option value="0" level="2">' + $.i18n.prop('0d3dcd210e07c8042720af18d1a8da96') + '</option>');
                }
                //渲染国家数据
                for(var i=0;i<adAr.length;i++){
                    if(this.opts.levelId1 == adAr[i].id){
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" level="'+adAr[i].addressLevel+'" selected>'+adAr[i].name+'</option>');
                        getProvinceByCountry(adAr[i].id,function(data){
                            if(data.status.status_code == 0){
                                _this.addressDisplay(data.result.ProvinceList,2);
                            }
                        });
                    }else{
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" level="'+adAr[i].addressLevel+'">'+adAr[i].name+'</option>');
                    }
                }
                if(this.opts.levelId2 != ''){
                    this.children('select[name=levelId2]').html('<option value="'+this.opts.levelId2+'">'+this.opts.levelName2+'</option>');
                }

                if(this.opts.levelId3 != 0){
                    this.children('select[name=levelId3]').show();
                    this.children('select[name=levelId3]').html('<option value="'+this.opts.levelId3+'">'+this.opts.levelName3+'</option>');
                }
                if(this.opts.levelId4 != 0){
                    this.children('select[name=levelId4]').show();
                    this.children('select[name=levelId4]').html('<option value="'+this.opts.levelId4+'">'+this.opts.levelName4+'</option>');
                }

            }else if(level == 2){
                this.children('select[name=levelId'+level+']').html('');
                if(this.opts.levelId2 > 0 && !changeFor){
                    this.children('select[name=levelId'+level+']').append('<option value="0" disabled>' + $.i18n.prop('9db15f3482ee4d3be7f3785e12e6799a') + '</option>');
                }else{
                    this.children('select[name=levelId'+level+']').append('<option value="0">' + $.i18n.prop('9db15f3482ee4d3be7f3785e12e6799a') + '</option>');
                }
                for(var i=0;i<adAr.length;i++){

                    //
                    if(this.opts.levelId2 == adAr[i].id){
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'" selected>'+adAr[i].provinceName+'</option>');
                        getCityByProvince(adAr[i].id,function(data){
                            if(data.status.status_code == 0){
                                _this.addressDisplay(data.result.CityList,3);
                            }
                        });

                    }else{
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'">'+adAr[i].provinceName+'</option>');
                    }

                    //

                    //this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'">'+adAr[i].provinceName+'</option>');

                }

            }else if(level == 3){
                this.children('select[name=levelId'+level+']').html('');
                if(this.opts.levelId3 > 0 && !changeFor){
                    this.children('select[name=levelId'+level+']').append('<option value="0" disabled>' + $.i18n.prop('dcace7f735bd72bae006b14a97dda088') + '</option>');
                }else{
                    this.children('select[name=levelId'+level+']').append('<option value="0">' + $.i18n.prop('dcace7f735bd72bae006b14a97dda088') + '</option>');
                }
                for(var i=0;i<adAr.length;i++){

                    //
                    if(this.opts.levelId3 == adAr[i].id){
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'" selected>'+adAr[i].cityName+'</option>');
                        /*getCityByProvince(adAr[i].id,function(data){
                         if(data.status.status_code == 0){
                         _this.addressDisplay(data.result.DistrictList,4);
                         }
                         });*/


                    }else{
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'">'+adAr[i].cityName+'</option>');
                    }
                    //


                    //this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'">'+adAr[i].cityName+'</option>');

                }
            }else if(level == 4){
                this.children('select[name=levelId'+level+']').html('');
                this.children('select[name=levelId'+level+']').append('<option value="0" disabled selected>' + $.i18n.prop('48aa95bff2045ab5d95f3d677488308f') + '</option>');
                for(var i=0;i<adAr.length;i++){
                    this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'">'+adAr[i].districtName+'</option>');
                }
            }
            //初次渲染回调函数
            if(_this.opts.oneCallback){
                _this.opts.oneCallback();
            }
        },
        addMonitor:function(){
            var _this = this;
            _this.children().on('change',function(){
                //当前层级
                var levelId = $(this).attr('name');
                //国家的层级
                var level = parseInt(_this.children().eq(0).find("option:selected").attr('level'));
                //经纬度
                var latitude = $(this).find("option:selected").attr('latitude');
                //经纬度
                var longitude = $(this).find("option:selected").attr('longitude');
                //当前选择的地址的id
                var value = $(this).find("option:selected").val();
                //当前
                var text = $(this).find("option:selected").text();
                var back = {};
                back.levels=level;
                back.value=value;
                back.text=text;
                (latitude!=undefined)?(back.latitude=latitude):"";
                (longitude!=undefined)?(back.longitude=longitude):"";

                if(levelId == 'levelId1'){
                    $('select[name=levelId1]').children('option').eq(0).attr("disabled","disabled");
                    back.level=1;
                    getProvinceByCountry(value,function(data){
                        if(data.status.status_code == 0){
                            _this.addressDisplay(data.result.ProvinceList,2,true);
                        }
                    });
                }else if(levelId == 'levelId2'){
                    $('select[name=levelId2]').children('option').eq(0).attr("disabled","disabled");
                    back.level=2;
                    //如果层级大于等于三级，就继续向下查询
                    if(level >= 3){
                        getCityByProvince(value,function(data){
                            if(data.status.status_code == 0){
                                _this.addressDisplay(data.result.CityList,3,true);
                            }
                        });
                    }
                }else if(levelId == 'levelId3'){
                    $('select[name=levelId3]').children('option').eq(0).attr("disabled","disabled");
                    back.level=3;
                    //如果层级大于等于三级，就继续向下查询
                    if(level == 4){
                        getDistrictByCity(value,function(data){
                            if(data.status.status_code == 0){
                                _this.addressDisplay(data.result.DistrictList,4);
                            }
                        });
                    }
                }else{
                    back.level=4;
                }
                //回调函数
                if(_this.opts.callback){
                    _this.opts.callback(back);
                }
                //根据当前国家的层级显隐相应的选择框
                if(level == 2){
                    _this.children('select[name=levelId3]').hide();
                    _this.children('select[name=levelId4]').hide();
                }else if(level == 3){
                    if(levelId == 'levelId1'){
                        _this.children('select[name=levelId3]').html('<option value="0">' + $.i18n.prop('dcace7f735bd72bae006b14a97dda088') + '</option>');
                    }
                    _this.children('select[name=levelId3]').show();
                    _this.children('select[name=levelId4]').hide();
                }else if(level == 4){
                    if(levelId == 'levelId1'){
                        _this.children('select[name=levelId3]').html('<option value="0">' + $.i18n.prop('dcace7f735bd72bae006b14a97dda088') + '</option>');
                        _this.children('select[name=levelId4]').html('<option value="0">' + $.i18n.prop('48aa95bff2045ab5d95f3d677488308f') + '</option>');
                    }
                    _this.children('select[name=levelId3]').show();
                    _this.children('select[name=levelId4]').show();
                }
            });
        }
    }
})(jQuery);

/*******************************************************************************
 * 功能：地址选择器
 * 作者：jame
 * 时间：2016-06-3 16:44
 ******************************************************************************/
(function ($) {
    $.fn.houseAddressSelect = function(options) {
        //定义变量信息
        options = jQuery.extend({
            levelName1        : '',       //默认：一级地址
            levelName2        : '',       //默认：二级地址
            levelName3        : '',       //默认：三级地址
            levelName4        : '',       //默认：四级地址
            levelId1        : '',       //默认：一级地址
            levelId2        : '',       //默认：二级地址
            levelId3        : '',       //默认：三级地址
            levelId4        : '',       //默认：四级地址
            callback          : null,     //默认：空的回调函数，返回参数(当前层级，层级的数据，总层级) input change回调函数
            oneCallback       : null      //默认：空的回调函数，返回参数(当前层级，层级的数据，总层级) 插件初次渲染回调函数
        }, options);
        this.opts = $.extend({}, $.fn.houseAddressSelect.defaults, options);
        $.fn.extend(this, addressSelect);
        //正式的调用以及渲染
        this.init();
    }

    var addressSelect = {
        init:function(){
            var _this = this;
            //获取一级国家列表
            getCountryList2(function(data){
                if(data.status.status_code == 0){
                    _this.addressDisplay(data.result.CountryList,1);
                }
            });
            //添加切换监听事件
            this.addMonitor();
        },
        addressDisplay:function(adAr,level,changeFor){
            var _this = this;
            if(level == 1){
                this.children('select[name=levelId'+level+']').html('');
                if(this.opts.levelId1 > 0){
                    this.children('select[name=levelId'+level+']').append('<option value="0" level="2" disabled>' + $.i18n.prop('0d3dcd210e07c8042720af18d1a8da96') + '</option>');
                }else{
                    this.children('select[name=levelId'+level+']').append('<option value="0" level="2">' + $.i18n.prop('0d3dcd210e07c8042720af18d1a8da96') + '</option>');
                }
                //渲染国家数据
                for(var i=0;i<adAr.length;i++){
                    if(this.opts.levelId1 == adAr[i].id){
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" level="'+adAr[i].addressLevel+'" selected>'+adAr[i].name+'</option>');
                        switch (adAr[i].addressLevel){
                            case '4':
                                this.children('select[name=levelId3]').html('<option value="0">' + $.i18n.prop('dcace7f735bd72bae006b14a97dda088') + '</option>');
                                _this.children('select[name=levelId3]').show();
                                this.children('select[name=levelId4]').html('<option value="0">' + $.i18n.prop('48aa95bff2045ab5d95f3d677488308f') + '</option>');
                                _this.children('select[name=levelId4]').show();
                            break;
                            case '3':
                                this.children('select[name=levelId3]').html('<option value="0">' + $.i18n.prop('dcace7f735bd72bae006b14a97dda088') + '</option>');
                                _this.children('select[name=levelId3]').show();
                            break;

                        }
                        getProvinceByCountry(adAr[i].id,function(data){
                            if(data.status.status_code == 0){
                                _this.addressDisplay(data.result.ProvinceList,2);
                            }
                        });
                    }else{
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'"  latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'" level="'+adAr[i].addressLevel+'">'+adAr[i].name+'</option>');
                    }
                }
                if(this.opts.levelId2 != ''){
                    this.children('select[name=levelId2]').html('<option value="'+this.opts.levelId2+'">'+this.opts.levelName2+'</option>');
                }
                if(this.opts.levelId3 != 0 && this.opts.levelId3 != 1){
                    this.children('select[name=levelId3]').show();
                    this.children('select[name=levelId3]').html('<option value="'+this.opts.levelId3+'">'+this.opts.levelName3+'</option>');
                }
                if(this.opts.levelId4 != 0){
                    this.children('select[name=levelId4]').show();
                    this.children('select[name=levelId4]').html('<option value="'+this.opts.levelId4+'">'+this.opts.levelName4+'</option>');
                }
            }else if(level == 2){
                this.children('select[name=levelId'+level+']').html('');
                if(this.opts.levelId2 > 0 && !changeFor){
                    this.children('select[name=levelId'+level+']').append('<option value="0" disabled>' + $.i18n.prop('9db15f3482ee4d3be7f3785e12e6799a') + '</option>');
                }else{
                    this.children('select[name=levelId'+level+']').append('<option value="0">' + $.i18n.prop('9db15f3482ee4d3be7f3785e12e6799a') + '</option>');
                }
                for(var i=0;i<adAr.length;i++){

                    if(this.opts.levelId2 == adAr[i].id){
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'" selected>'+adAr[i].provinceName+'</option>');

                        getCityByProvince(adAr[i].id,function(data){
                            if(data.status.status_code == 0){
                                _this.addressDisplay(data.result.CityList,3);
                            }
                        });


                    }else{
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'">'+adAr[i].provinceName+'</option>');

                    }

                }
            }else if(level == 3){
                this.children('select[name=levelId'+level+']').html('');
                if(this.opts.levelId3 > 0 && !changeFor){
                    this.children('select[name=levelId'+level+']').append('<option value="0" disabled>' + $.i18n.prop('dcace7f735bd72bae006b14a97dda088') + '</option>');
                }else{
                    this.children('select[name=levelId'+level+']').append('<option value="0">' + $.i18n.prop('dcace7f735bd72bae006b14a97dda088') + '</option>');
                }
                for(var i=0;i<adAr.length;i++){
                    if(this.opts.levelId3 == adAr[i].id){
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'" selected>'+adAr[i].cityName+'</option>');
                        getDistrictByCity(adAr[i].id,function(data){
                         if(data.status.status_code == 0){
                         _this.addressDisplay(data.result.DistrictList,4);
                         }
                         });
                    }else{
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'">'+adAr[i].cityName+'</option>');
                    }

                }
            }else if(level == 4){
                this.children('select[name=levelId'+level+']').html('');

                if(this.opts.levelId4 > 0 && !changeFor){
                    this.children('select[name=levelId'+level+']').append('<option value="0" disabled selected>' + $.i18n.prop('77e6054eb341a6084e334578e83ef4f8') + '</option>');
                }else{
                    this.children('select[name=levelId'+level+']').append('<option value="0" disabled selected>' + $.i18n.prop('77e6054eb341a6084e334578e83ef4f8') + '</option>');
                }
                for(var i=0;i<adAr.length;i++){
                    if(this.opts.levelId4 == adAr[i].id){
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'" selected>'+adAr[i].districtName+'</option>')
                    }else{
                        this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'">'+adAr[i].districtName+'</option>');
                    }
                }
                /*this.children('select[name=levelId'+level+']').append('<option value="0" disabled selected>' + $.i18n.prop('48aa95bff2045ab5d95f3d677488308f') + '</option>');
                for(var i=0;i<adAr.length;i++){
                    this.children('select[name=levelId'+level+']').append('<option value="'+adAr[i].id+'" latitude="'+adAr[i].latitude+'" longitude="'+adAr[i].longitude+'">'+adAr[i].districtName+'</option>');
                }*/
            }
            //初次渲染回调函数
            if(_this.opts.oneCallback){
                _this.opts.oneCallback();
            }
        },
        addMonitor:function(){
            var _this = this;
            _this.children().on('change',function(){
                //当前层级
                var levelId = $(this).attr('name');
                //国家的层级
                var level = parseInt(_this.children().eq(0).find("option:selected").attr('level'));
                //经纬度
                var latitude = $(this).find("option:selected").attr('latitude');
                //经纬度
                var longitude = $(this).find("option:selected").attr('longitude');
                //当前选择的地址的id
                var value = $(this).find("option:selected").val();
                //当前
                var text = $(this).find("option:selected").text();
                var back = {};
                back.levelId = levelId;
                back.levels=level;
                back.value=value;
                back.text=text;
                (latitude!=undefined)?(back.latitude=latitude):"";
                (longitude!=undefined)?(back.longitude=longitude):"";

                if(levelId == 'levelId1'){
                    $('select[name=levelId1]').children('option').eq(0).attr("disabled","disabled");
                    back.level=1;
                    getProvinceByCountry(value,function(data){
                        if(data.status.status_code == 0){
                            _this.addressDisplay(data.result.ProvinceList,2,true);
                        }
                    });
                }else if(levelId == 'levelId2'){
                    $('select[name=levelId2]').children('option').eq(0).attr("disabled","disabled");
                    back.level=2;
                    //如果层级大于等于三级，就继续向下查询
                    if(level >= 3){
                        _this.children('select[name=levelId4]').html('<option value="0">' + $.i18n.prop('48aa95bff2045ab5d95f3d677488308f') + '</option>');
                        getCityByProvince(value,function(data){
                            if(data.status.status_code == 0){
                                _this.addressDisplay(data.result.CityList,3,true);
                            }
                        });
                    }
                }else if(levelId == 'levelId3'){
                    $('select[name=levelId3]').children('option').eq(0).attr("disabled","disabled");
                    back.level=3;
                    //如果层级大于等于三级，就继续向下查询
                    if(level == 4){
                        getDistrictByCity(value,function(data){
                            if(data.status.status_code == 0){
                                _this.addressDisplay(data.result.DistrictList,4);
                            }
                        });
                    }
                }else{
                    back.level=4;
                }
                //change回调函数
                if(_this.opts.callback){
                    _this.opts.callback(back);
                }
                //根据当前国家的层级显隐相应的选择框
                if(level == 2){
                    _this.children('select[name=levelId3]').hide();
                    _this.children('select[name=levelId4]').hide();
                }else if(level == 3){
                    if(levelId == 'levelId1'){
                        _this.children('select[name=levelId3]').html('<option value="0">' + $.i18n.prop('dcace7f735bd72bae006b14a97dda088') + '</option>');
                    }
                    _this.children('select[name=levelId3]').show();
                    _this.children('select[name=levelId4]').hide();
                }else if(level == 4){
                    if(levelId == 'levelId1'){
                        _this.children('select[name=levelId3]').html('<option value="0">' + $.i18n.prop('dcace7f735bd72bae006b14a97dda088') + '</option>');
                        _this.children('select[name=levelId4]').html('<option value="0">' + $.i18n.prop('48aa95bff2045ab5d95f3d677488308f') + '</option>');
                    }
                    _this.children('select[name=levelId3]').show();
                    _this.children('select[name=levelId4]').show();
                }
            });
        }
    }
})(jQuery);





/*******************************************************************************
 * 功能：生日选择器
 * 作者：jame
 * 时间：2016-05-26 15:04
 ******************************************************************************/
(function ($) {
    $.fn.birthdaySelect = function(options) {
        //定义变量信息
        options = jQuery.extend({
            year        : '',       //默认：一级地址
            month       : '',       //默认：二级地址
            day         : '',       //默认：三级地址
            yearStart   : 1930,       //默认：四级地址
            callback    : null,     //默认：空的回调函数，返回参数(当前层级，层级的数据，总层级)
        }, options);
        this.opts = $.extend({}, $.fn.birthdaySelect.defaults, options);
        $.fn.extend(this, birthdaySelect);
        //正式的调用以及渲染
        this.init();
    }

    var birthdaySelect = {
        init:function(){
            //添加切换监听事件
            this.birthdayDisplay();
            //添加切换监听事件
            this.addMonitor();
        },
        birthdayDisplay:function(adAr,level){
            var oDate = new Date(); //实例一个时间对象；
            var nowYear = oDate.getFullYear();   //获取系统的年；
            this.find('select[name=year]').html('');
            this.find('select[name=year]').append('<option value="" selected>' + $.i18n.prop('56c918f70eb2faf7eaec7644191c03ce') + '</option>');
            for(var i=this.opts.yearStart;i<=nowYear;i++){
                if(this.opts.year == i){

                    this.find('select[name=year]').append('<option value="'+i+'" selected>'+i+'</option>');
                }else{
                    this.find('select[name=year]').append('<option value="'+i+'">'+i+'</option>');
                }
            }
            this.find('select[name=month]').html('');
            this.find('select[name=month]').append('<option value="" selected>' + $.i18n.prop('430021ee0b330b37a8843e16f372b958') + '</option>');
            for(var i=1;i<=12;i++){
                var value = (i<10)?('0'+i):i;
                if(parseInt(this.opts.month) == i){
                    this.find('select[name=month]').append('<option value="'+value+'" selected>'+i+$.i18n.prop('0e91f3f44857655aa74e049ea8ff60ed') + '</option>');
                }else{
                    this.find('select[name=month]').append('<option value="'+value+'">'+i+$.i18n.prop('0e91f3f44857655aa74e049ea8ff60ed')+ '</option>');
                }
            }

            var day = 31;
            //判断如果有传入日期的情况下
            if(this.opts.year != '' && (this.opts.month == '02' || this.opts.month == '2') && this.opts.day != ''){
                if(this.isLeapYear(this.opts.year)){
                    day = 29;
                }else{
                    day = 28;
                }
            }else if(this.opts.month == '04' || this.opts.month == '06' || this.opts.month == '09' || this.opts.month == '11'){
                day = 30;
            }
            this.find('select[name=day]').html('');
            this.find('select[name=day]').append('<option value="" selected>' + $.i18n.prop('4e9db45afaa6e8304f363f4b5186f05b') + '</option>');
            for(var i=1;i<=day;i++){
                var value = (i<10)?('0'+i):i;
                if(parseInt(this.opts.day) == i){
                    this.find('select[name=day]').append('<option value="'+value+'" selected>'+i+$.i18n.prop('9cca2bcf39b78274aaea8f5fd17b3fc5') + '</option>');
                }else{
                    this.find('select[name=day]').append('<option value="'+value+'">'+i+$.i18n.prop('9cca2bcf39b78274aaea8f5fd17b3fc5') + '</option>');
                }
            }
        },
        isLeapYear:function(year) {
            year = parseInt(year);
            return (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0);
        },
        addMonitor:function(){
            var _this = this;
            _this.children().on('change',function(){
                //当前层级
                var dayName = $(this).attr('name');
                var year = _this.find('select[name=year]').find("option:selected").val();
                var month = _this.find('select[name=month]').find("option:selected").val();
                var day = _this.find('select[name=day]').find("option:selected").val();
                if(dayName == 'month' || dayName == 'year'){
                    var dayNum = 31;
                    if(_this.isLeapYear(year) && month == '02'){
                        dayNum = 29;
                    }else if(month == '02'){
                        dayNum = 28;
                    }
                    if(month == '04' || month == '06' || month == '09' || month == '11'){
                        dayNum = 30;
                    }
                    _this.find('select[name=day]').html('');
                    _this.find('select[name=day]').append('<option value="" selected>' + $.i18n.prop('4e9db45afaa6e8304f363f4b5186f05b') + '</option>');
                    for(var i=1;i<=dayNum;i++){
                        var value = (i<10)?('0'+i):i;
                        if(parseInt(day) == i){
                            _this.find('select[name=day]').append('<option value="'+value+'" selected>'+i+$.i18n.prop('9cca2bcf39b78274aaea8f5fd17b3fc5') + '</option>');
                        }else{
                            _this.find('select[name=day]').append('<option value="'+value+'">'+i+$.i18n.prop('9cca2bcf39b78274aaea8f5fd17b3fc5') + '</option>');
                        }
                    }
                }
                //回调函数
                if(_this.opts.callback){
                    _this.opts.callback(year+'-'+month+'-'+day);
                }
            });
        }
    }
})(jQuery);



/*******************************************************************************
 * 功能：网站头部的监听程序(从reservation.js里剪切)
 * 作者：jiph
 * 时间：2016-05-26 21:07
 ******************************************************************************/
function addLisenerForHeader(){
    /*
     * 移动端点击导航侧拉页面显隐
     * for all page
     */
    $('.popup-nav').click(function(){
        if($('.xs-nav').css('display')){
            $('body,.xs-overlay').css('overflow','hidden');
            $(".xs-nav").show( 'slide', {}, 300 );
            $(".xs-header .xs-overlay").fadeIn(100);
            $('.apply-for-room').hide();//申请预订按钮隐藏
            $('.apply-for-room').removeClass('visible-xs-block');//申请预订按钮隐藏
        }
    });
    $('.xs-overlay,.xs-nav-header-back').click(function(){
        $('body').css('overflow','auto');
        $(".xs-nav").hide( 'slide', {}, 500 );
        $(".xs-header .xs-overlay").fadeOut(100);
        $('.apply-for-room').show();//申请预订按钮显示
        $('.apply-for-room').addClass('visible-xs-block');//申请预订按钮显示
    });

    /*
     * 所有日历页面，点击日期其他地方隐藏插件
     * for all page
     */
    $(document).click(function(){
        if($('.search_box').is(':visible')){
            $('.search_box').hide();
        }
    });


    //$('input[name=keyword],input[name=keyword2]').click(function(){
    //    var keys = $(this).attr('id');
    //    checkKeyword(keys);
    //});
    //$('input[name=keyword],input[name=keyword2]').keyup(function(){
    //    var keys = $(this).attr('id');
    //    checkKeyword(keys);
    //});
    ////点击如果文字条件改编立马变成关键词搜索
    //$('input[name=keyword],input[name=keyword2]').change(function(){
    //    $('input[name=type]').val('keyword');
    //    $('input[name=level]').val('');
    //    $('input[name=levelid]').val('');
    //});
    //$('.search_box').on('click','.key',function(e){
    //    e.stopPropagation();
    //    var host = window.location.host;
    //    if($(this).attr('id') == '-1' || $(this).attr('data-level') == '10'){
    //        //如果是第一个就直接按照第一个关键词进行查询
    //        var adds = '';
    //        if($(this).attr('id') == '-1'){
    //            keyword = $(this).children('span').html();
    //        }else{
    //            keyword = $(this).html();
    //            $('input[name=keyword]').val(keyword);
    //            adds = '?land='+$(this).attr('data-id');
    //        }
    //        //设定默认的查询条件
    //        $('input[name=type]').val('keyword');
    //        window.location.replace("//"+host+"/kw/"+keyword+"/"+adds);
    //    }else if($(this).attr('data-level') == '11'){
    //        //景点的情况
    //        //如果是第二个就按照地区进行查
    //        var keyword = $(this).html();
    //        var level = $(this).attr('data-level');
    //        var levelid = $(this).attr('data-id');
    //        var pinyin = $(this).attr('data-pinyin');
    //
    //        //设定默认的查询条件
    //        $('input[name=type]').val('level');
    //        $('input[name=level]').val(level);
    //        $('input[name=levelid]').val(levelid);
    //        //var city = 'beijign';
    //        window.location.replace("//"+host+"/"+pinyin+"/land"+levelid+"/");
    //    }else{
    //        //如果是第二个就按照地区进行查
    //        var keyword = $(this).html();
    //        var level = $(this).attr('data-level');
    //        var levelid = $(this).attr('data-id');
    //        var pinyin = $(this).attr('data-pinyin');
    //        //设定默认的查询条件
    //        $('input[name=type]').val('level');
    //        $('input[name=level]').val(level);
    //        $('input[name=levelid]').val(levelid);
    //        window.location.replace("//"+host+"/"+pinyin+"/");
    //    }
    //    $('input[name=keyword]').val(keyword);
    //    $('.search_box').hide();
    //});
    //function checkKeyword(keys){
    //    if(!keys)
    //        return;
    //    var keyword = $('input[name='+keys+']').val();
    //    //keyword = keyword.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    //    if(keyword.length>0){
    //        getLevelByKeywords(keyword,function(data){
    //            var checkClass = '';
    //            if(keys == 'keyword'){
    //                checkClass = '.search_box.col-sm-12';
    //            }else{
    //                checkClass = '.search_box.col-xs-12';
    //            }
    //            $(checkClass).show();
    //            $(checkClass).children('.check_key').html('');
    //            $(checkClass).children('.check_key').append('<li class="key" id="-1">搜索"<span>'+keyword+'</span>"</li>');
    //            var list = data.result.levelList;
    //            for(var i=0;i<list.length;i++){
    //                if(list[i].level==11)
    //                    $(checkClass).children('.check_key').append('<li class="key" id="'+i+'" data-level="'+list[i].level+'" data-id="'+list[i].id+'" data-pinyin="'+list[i].cityNamePinyin+'">'+list[i].name+'</li>');
    //                else
    //                    $(checkClass).children('.check_key').append('<li class="key" id="'+i+'" data-level="'+list[i].level+'" data-id="'+list[i].id+'" data-pinyin="'+list[i].pinyin+'">'+list[i].name+'</li>');
    //            }
    //            $('input[name=type]').val('keyword');
    //        });
    //    }else{
    //        if($('.search_box').is(':visible')){
    //            $('.search_box').hide();
    //        }
    //    }
    //}
    ////当输入框失去焦点的时候
    //$('input[name=keyword],input[name=keyword2]').focusout(function(){
    //    var keys = $(this).attr('id');
    //    if(!keys)
    //        return;
    //    $('input[name='+keys+']').removeClass('keyword_input');
    //});
    //$('input[name=keyword]').keyup(function(){
    //    var keys = $(this).attr('id');
    //    if(!keys)
    //        return;
    //    if($('input[name='+keys+']').val().length>0){
    //        $('input[name='+keys+']').removeClass('keyword_input');
    //    }
    //});
    //























    /*鼠标移入事件*/
    $('.show-header-nav').bind('mouseover',function(){
        $('.glyphicon-triangle-bottom').css('display','none');
        $('.glyphicon-triangle-top').css('display','inline-block');
    });
    $('.show-header-nav').bind('mouseout',function(){
        $('.glyphicon-triangle-bottom').css('display','inline-block');
        $('.glyphicon-triangle-top').css('display','none');
    });
}

////搜索提交判断
//function submitForSearch(){
//    if($('input[name=keyword]').val().trim() == '' || $('input[name=keyword]').val().trim() == null){
//        $('input[name=keyword]').addClass('keyword_input');
//        $('input[name=keyword]').focus();
//    }else{
//        var host = window.location.host;
//        if($('input[name=type]').val().trim() == 'keyword'){
//            //如果是第一个就直接按照第一个关键词进行查询
//            var keyword = $('input[name=keyword]').val().trim();
//            //设定默认的查询条件
//            window.location.replace("//"+host+"/kw/"+keyword+"/");
//        }else{
//            //如果是第二个就按照地区进行查
//            var pinyin = $('input[name=pinyin]').val().trim();
//            window.location.replace("//"+host+"/"+pinyin+"/");
//        }
//    }
//    return false;
//}

/*******************************************************************************
 * 功能：根据关键词获取列表
 * 参数：keyword(关键词) fn(回调函数)
 * 作者：jame
 * 时间：2016-05-25 16:45
 ******************************************************************************/
function getLevelByKeywords(keyword,fn){
    if(!keyword){
        var status = {};
        status.status_code = -1;
        status.status_reason = $.i18n.prop('05b5f38f495d677e95058be16d897b5f');
        if(fn){
            fn(status);
        }
        return;
    }
    var param = {};
    param.keyword = keyword;
    var value = JSON.stringify(param);
    treatData('house/getLevelByKeywords',value,function(data,url){
        if(fn){
            fn(data);
        }
    },function(){
        var status = {};
        status.status_code = -1;
        status.status_reason = $.i18n.prop('282198dd41f3b95deb78102015c093ef');
        if(fn){
            fn(status);
        }
    });
}



/*******************************************************************************
 * 功能：判断ie版本
 * 作者：pwz
 * 时间：2016-05-28 12:13
 ******************************************************************************/
function disIe (str) {
    var isIeUser = navigator.userAgent.indexOf('MSIE') > 0 ? 1 : 0;
    var isIeAppName =  navigator.appName.indexOf('Microsoft') !=-1 ? 1 : 0;
    if(isIeUser && isIeAppName){
        var b_version = navigator.appVersion;
        var version = b_version.split(";");
        var trim_Version=version[1].replace(/[ ]/g,"");
        if(trim_Version==str){
            return true;
        }else{
            return false;
        }
    }
}


/*******************************************************************************
 * 功能：给一个二维数组进行排序
 * 参数：arr(要排序的数组) field(暂时不管用) order(排序的顺序)
 * 作者：jame
 * 时间：2016-05-30 13:24
 ******************************************************************************/
function listSortBy(arr, field, order){
    var refer = [], result=[], order = order=='asc'?'asc':'desc', index;
    for(i=0; i<arr.length; i++){
        refer[i] = arr[i].publish_time+'$'+i;
    }
    refer.sort();
    if(order=='desc') refer.reverse();
    for(i=0;i<refer.length;i++){
        index = refer[i].split('$')[1];
        result[i] = arr[index];
    }
    return result;
}

/*******************************************************************************
 * 功能：字符串进行转码
 * 参数：str(要转码的字符串)
 * 作者：jame
 * 时间：2016-05-30 14:35
 ******************************************************************************/
function characterTransition(str){
    str = str.replace(/\'/g,  '\'');
    str = str.replace(/\"/g, "\"");
    str = str.replace(/&/g, "%26");
    str = str.replace(/#/g, "%23");
//    str = str.replace(/ /g, "%20");
    return str;
}

/*******************************************************************************
 * 功能：判断数组是否包含某个元素
 * 参数：array(要判断的数组) value(是否包含的方法)
 * 作者：jame
 * 时间：2016-05-30 18:35
 ******************************************************************************/
function in_array(array,value){
    for(k=0;k<array.length;k++){
        if(value == array[k])
            return true;
    }
    return false;
}


/*******************************************************************************
 * 功能：保存用户的单个信息
 * 参数：
 * 作者：djm (由pwz 2016-05-31 11:50 从base中提出)
 * 时间：2016-05-31 11:50
 ******************************************************************************/
function userInforSingleSave(key,value){
    var myDate = new Date();
    $.post("/user/c_editUserInforSingle", {key:key,value:value,date:myDate},function(data){
        if(value != ''){
            var img = "//"+$("#picture_host").attr('value')+"/get.php?pn="+value+"&pt=0&st=medium";
            $(".media-photo").children('img').attr('src',img);
        }else{
            var img = "/images/user_pic-225x225.png";
            $(".media-photo").children('img').attr('src',img);
            $('.percent').html('0%');
        }
    }, "json");
}
/*******************************************************************************
 * 功能：职业选择器
 * 作者：gyf
 * 时间：2016-06-02
 ******************************************************************************/
(function ($) {
    $.fn.jobSelect = function(options) {
        //定义变量信息
        options = jQuery.extend({
            joblevelName1        : '',       //默认：一级
            joblevelName2        : '',       //默认：二级
            joblevelId1        : '',       //默认：一级
            joblevelId2        : '',       //默认：二级
            callback          : '',     //默认：空的回调函数，返回行业ID和职业ID
        }, options);
        this.opts = $.extend({}, $.fn.jobSelect.defaults, options);
        $.fn.extend(this, jobSelect);
        //正式的调用以及渲染
        this.init();
    }

    var jobSelect = {
        init:function(){
            var _this = this;
            getIndustryList(function(data){
                if(data.status.status_code == 0){
                    _this.jobDisplay(data.result.ProfessionList,1);
                }
            });
            //添加切换监听事件
            this.addMonitor();
        },

        jobDisplay:function(adAr,level,changeFor){
            var _this = this;
            if(level == 1){
                this.children('select[name=joblevelId'+level+']').html('');
                //console.log(this.opts.joblevelId1);
                if(this.opts.joblevelId1>0){
                    this.children('select[name=joblevelId'+level+']').append('<option value="0" disabled>' + $.i18n.prop('dfee0fc5451fd5b3efba53b385aff149') + '</option>');
                }else{
                    this.children('select[name=joblevelId'+level+']').append('<option value="0">' + $.i18n.prop('4eecdd80d5e3ae4331f9d3468f548465') + '</option>');
                }
                //渲染数据
                for(var i=0;i<adAr.length;i++){
                    if(this.opts.joblevelId1 == adAr[i].industryId){
                        this.children('select[name=joblevelId'+level+']').append('<option value="'+adAr[i].industryId+'"  selected>'+adAr[i].industryName+'</option>');
                        getJobByIndustryId(adAr[i].industryId,function(data){
                            if(data.status.status_code == 0){
                                _this.jobDisplay(data.result.ProfessionList,2);
                            }
                        });
                    }else{
                        this.children('select[name=joblevelId'+level+']').append('<option value="'+adAr[i].industryId+'" >'+adAr[i].industryName+'</option>');
                    }
                }
                if(this.opts.joblevelName2 != ''){
                    this.children('select[name=joblevelId2]').html('<option value="'+this.opts.joblevelId2+'">'+this.opts.joblevelName2+'</option>');
                }

            }
            else if(level == 2){
                this.children('select[name=joblevelId'+level+']').html('');
                if(!changeFor){
                    this.children('select[name=joblevelId'+level+']').append('<option value="0" disabled>' + $.i18n.prop('62d3b72a913164e2a23d8729d0421af1') + '</option>');
                }else{
                    this.children('select[name=joblevelId'+level+']').append('<option value="0">' + $.i18n.prop('d318be29ba887a0e2707b1c5e10d7bc7') + '</option>');
                }

                for(var i=0;i<adAr.length;i++){
                    if(this.opts.joblevelId2 == adAr[i].id){
                        this.children('select[name=joblevelId'+level+']').append('<option value="'+adAr[i].id+'"  selected>'+adAr[i].jobName+'</option>');

                    }else{
                        this.children('select[name=joblevelId'+level+']').append('<option value="'+adAr[i].id+'">'+adAr[i].jobName+'</option>');

                    }
                }
            }
        },

        addMonitor:function(){
            var _this = this;
            _this.children().on('change',function(){
                //当前层级
                var joblevelId = $(this).attr('name');

                //当前选择的的id
                var value = $(this).find("option:selected").val();
                //当前


                if(joblevelId == 'joblevelId1'){
                    $('select[name=joblevelId1]').children('option').eq(0).attr('disabled','disabled');
                    getJobByIndustryId(value,function(data){
                        if(data.status.status_code == 0){
                            _this.jobDisplay(data.result.ProfessionList,2,true);
                        }
                    });
                }else if(joblevelId == 'joblevelId2'){
                    $('select[name=joblevelId2]').children('option').eq(0).attr('disabled','disabled');
                }

                var back = {};
                var industryId;
                var id;
                industryId = $(_this).find("option:selected").val();
                id = $("#job").find("option:selected").val();

                back.industryId = industryId;
                back.id = id;

                //回调函数
                if(_this.opts.callback){
                    _this.opts.callback(back);
                }
            });
        }
    }
})(jQuery);





/*******************************************************************************
 * 功能：添加未完善资料检测(从base上复制)
 * 作者：jiph
 * 时间：2016-02-25
 ******************************************************************************/
function addListenNotPerfect(){
    //追踪路径返回页面
    var bJump = true;
    if(parseInt($.cookie('perfectInformationstatus')) == 0) {
        bJump = false;
        var history = location.pathname;
        window.location.replace("/register/p_completion?history="+history);

    }
    return bJump;
}



/**自定义 搜索框
 * opt 包含要绑定的input，搜索项的box
 * ***/

// var defineSelect = {
//
//     init: function(opt,fn) {
//        if(opt.input.length==0||opt.box.length==0)
//            return;
//
//
//         opt.input.parent().click(function(){
//
//             if(opt.box.css('display')=='none')
//             {
//                 opt.box.stop().slideDown();
//             }
//             else {
//                 opt.box.stop().slideUp();
//             }
//         });
//
//         opt.box.on('click','li',function(){
//             var $this=$(this);
//             opt.input.val($this.html()).attr('numvalue',$this.attr('value'));
//             if(fn)
//                 return fn();
//         })
//         $('body').on('click',function(e){
//             if($(e.target).hasClass('defineselectinputbox') || $(e.target).parents('.defineselectinputbox').length>0)
//                 return;
//             if(opt.box.css('display')=='block')
//                 opt.box.stop().slideUp();
//
//         })
//     }
// }


/***将日期进行转换
 * str:如20160715改为2016-07-15
 *jiph 160630
 */
function dataChangeForUse(str) {
    if(!str)
        return '';
    if (str.length == 8) {
        return str.substr(0, 4) + '-' + str.substr(4, 2) + '-' + str.substr(6, 2);
    } else {
        return str.replace('-', '').replace('-', '');
    }


}







/******
 * 生成展示信息 (预订) jiph 160701
 * **/
function checkPrice(currency_symbol, price, priceList) {
    var boo = true;
    for (var i = 0; i < priceList.length; i++) {
        if (price == priceList[i].price) {
            priceList[i].num++;
            priceList[i].priceName = currency_symbol + priceList[i].price + '*' + priceList[i].num + $.i18n.prop('2a668c21c6700e683773fa28c9ab4b3c');
            priceList[i].totalPrice = currency_symbol + (parseInt(priceList[i].price) * parseInt(priceList[i].num));
            boo = false;
        }
    }
    if (boo) {
        var hh = {
            "price": price,
            "priceName": currency_symbol + price + $.i18n.prop('ba61401f60eaab451e8cd2e739aa7a09'),
            "num": 1,
            "totalPrice": currency_symbol + price
        };
        priceList.push(hh);
    }
    return priceList;
}


//listTime('20150629','20150715');
/*
 * 给一组时间数据，列出时间的中间列表 (预订) jiph 160701
 *
 * for all
 */
function listTime(oDate1, oDate2) {
    if (oDate1.length > 8) {
        var y1 = oDate1.substring(0, 4);
        var m1 = parseInt(oDate1.substring(5, 7)) - 1;
        var d1 = oDate1.substring(8, 10);
    } else {
        var y1 = oDate1.substring(0, 4);
        var m1 = parseInt(oDate1.substring(4, 6) - 1);
        var d1 = oDate1.substring(6, 8);
    }
    var date1 = new Date(y1, m1, d1);
    if (oDate2.length > 8) {
        var y2 = oDate2.substring(0, 4);
        var m2 = parseInt(oDate2.substring(5, 7) - 1);
        var d2 = oDate2.substring(8, 10);
    } else {
        var y2 = oDate2.substring(0, 4);
        var m2 = parseInt(oDate2.substring(4, 6) - 1);
        var d2 = oDate2.substring(6, 8);
    }
    var date2 = new Date(y2, m2, d2);
    var calendar = new Array();
    var i = 0;
    while (date1 < date2) {
        calendar[i++] = date1.getFullYear() + '' + (((date1.getMonth() + 1) > 9) ? (date1.getMonth() + 1) : ('0' + (date1.getMonth() + 1))) + '' + ((date1.getDate() > 9) ? date1.getDate() : ('0' + date1.getDate()));
        date1.setDate(date1.getDate() + 1);
    }
    return calendar;
}


/**
 * 固定元素的位置
 * obj要固定的目标元素
 * className 自定义的position:fixed类，top要自已设置
 * */
function checkWindowHeight_new(obj,className){

    var iTop = obj.offset().top;
    //var objheight=obj.height();
    var imgs=obj.find('img');
    var objheight=imgs.length*205+imgs.length*60;

    var bodyheight=parseInt($('body').height());
    var footerheight=parseInt($('.footer-box').height())+57;

    if($(window).width() >600 && $('body').height>1000){

        window.onresize = window.onscroll = function(){
            var wiTop = (document.documentElement.scrollTop || document.body.scrollTop);
            if(wiTop >= iTop ){

                if(bodyheight-wiTop>=objheight+footerheight)
                {
                    obj.addClass(className);
                }
                else {
                    obj.removeClass(className);
                }

              console.log('objheight:'+objheight+' wiTop:'+wiTop+' bodyheight:'+bodyheight+' footerheight:'+footerheight);


            }else{
                obj.removeClass(className);
            }
        }
    }
}

/**
 * 更改谷歌地图左下角的图标样式
 * */
function waitChangeGoogleInforByJquery(){
    setTimeout(function(){
        changeInforFromGoogleByJquery();
    },500);
    setTimeout(function(){
        changeInforFromGoogleByJquery();
    },1000);
    setTimeout(function(){
        changeInforFromGoogleByJquery();
    },2000);
    setTimeout(function(){
        changeInforFromGoogleByJquery();
    },5000);
    setTimeout(function(){
        changeInforFromGoogleByJquery();
    },10000);
    setTimeout(function(){
        changeInforFromGoogleByJquery();
    },30000);
    //更改地图信息
    function changeInforFromGoogleByJquery(){
        $('.gm-style-cc').hide();
        var imgIndex = parseInt($('.gm-style.gm-china').children('div').length)-1;
        $('.gm-style.gm-china').children('div').eq(imgIndex).children('a').attr('href','JavaScript:void(0);');
        $('.gm-style.gm-china').children('div').eq(imgIndex).children('a').attr('target','_self');
        $('.gm-style.gm-china').children('div').eq(imgIndex).children('a').children('div').children('img').attr('src','/images/guge/googlemark2.png').css('width','120px');
        $('.gm-style.gm-china').children('div').eq(imgIndex).children('a').children('div').css('width','120px');
    }
}



/***** 根据图片大小调整图片位置 jiph 0728
 * obj 要设置的图片
 * parent 图片的祖先节点（可以是父节点 ，如 '.box'）
 * w 图片宽度如果小于这个值，则调整图片位置，如果不设置，会默认为parent 的宽度
 *  h 图片高度如果小于这个值，则调整图片位置，如果不设置，会默认为parent 的高度
 * *****/

function changeBigImg(obj,parent,w,h){
    var container = obj.parents(parent);
    var w_x = container.width();
    var w_y = container.height();
    var src = obj.attr('src');
    var theImage = new Image();
    theImage.src = src;
    var w=w?w:w_x;
    var h=h?h:w_y;
    theImage.onload = function(){
        //原始宽度
        var img_width = this.width;
        //原始高度
        var img_height = this.height;
        if(img_width<w || img_height<h)
        {
            if((img_width/img_height) - (w_x/w_y) > 0.2){
                //伸长后的高度
                var fu_height = w_x*img_height/img_width;
                //求偏移量
                var offset_y = (fu_height-w_y)/2;
                obj.css({'width':'100%','height':fu_height+'px','margin-top':-offset_y+'px','margin-left':'0px'});
            }else if((img_width/img_height) - (w_x/w_y) < -0.2){
                //伸长后的高度
                var fu_width = w_y*img_width/img_height;
                //求偏移量
                var offset_x = (fu_width-w_x)/2;
                obj.css({'height':'100%','width':fu_width+'px','margin-left':-offset_x+'px','margin-top':'0px'});
            }else{
                obj.css({'height':'100%','width':'100%','margin-top':'0px','margin-left':'0px'});
            }

        }
        else {
            return;
        }


    }
}



//仪表盘功能
function rotateMeter(nIndex,obj) {
    if(disIe ("MSIE8.0") || disIe ("MSIE7.0")) {
        $('.pointer').hide();
    }
    var degree,nowDegree;
    var startBranch = 350,
        fiveBranch = 550,
        sevenBranch = 700,
        endBranch = 950,
        startDegree = -108,
        fiveDegree = -66,
        sevenDegree = 66;
    endDegree = 108,
        s1 =null,t1 = null;
    var content = {
        position: 'default',
        grade: '',
        text:'',
        spanText1:'',
        spanText2:''
    };
    if(typeof(obj) == 'object') {
        $.extend(content,obj);
    }
    if(content.position != 'default' && content.position != 'landlord'){
        $('.meterPar').css({
            "marginLeft" : -6,
            "top": 30
        }).find('.meterIcon').css({
            "right": 'inherit',
            "left" : 44
        })
    }else if(content.position == 'landlord'){
        $('.meterPar').css({
            left:79,
            "top": 30
        })
    }
    if(content.text == ''){
        $('.meterPar').css('height',346);
        $('.meterImg').css('height',232);
    }
    $('.branchGrade').html(content.grade);
    $('.branchText').html(content.text);
    $('.meterTip span').eq(0).html(content.spanText1);
    $('.meterTip span').eq(1).html(content.spanText2);
    if(nIndex > startBranch && nIndex <= endBranch) {
        clearInterval(s1);
        s1 = setInterval(function(){ //分数增加
            startBranch++;
            if(startBranch >= nIndex){
                clearInterval(s1);
            }
            $('.branchNum').html(startBranch);
        },3);
        clearInterval(t1);
        t1 = setInterval(function(){ //Run
            move1(nIndex);
        },10);
    }else{
        return;
    }
    function move1(nIndex){
        startDegree = startDegree + 1;
        if(nIndex > fiveBranch){
            eachDegree = (fiveBranch - startBranch)/(Math.abs(-108) - Math.abs(fiveDegree)); //每一角度占的刻度
            nowDegree = (fiveBranch - startBranch)/eachDegree -108;
            if( startDegree >= nowDegree) {
                clearInterval(t1);
                t2 = setInterval(function(){
                    move2(nIndex);
                },10);
            }

        }else{
            eachDegree = (fiveBranch - startBranch)/(Math.abs(startDegree) - Math.abs(fiveDegree)); //每一角度占的刻度
            nowDegree = (nIndex-startBranch)/eachDegree + startDegree;
            if(startDegree >= nowDegree) {
                clearInterval(t1);
            }
        }
        rotateFn(startDegree);
    };
    function move2(nIndex){
        fiveDegree = fiveDegree + 1;
        if(nIndex - sevenBranch > 0){ //第三阶段
            eachDegree = (sevenBranch - fiveBranch)/(Math.abs(-66) + Math.abs(sevenDegree)); //每一角度占的刻度
            nowDegree = (sevenBranch-fiveBranch)/eachDegree - 66;
            if(fiveDegree >= nowDegree) {
                clearInterval(t2);
                t3 = setInterval(function(){
                    move3(nIndex);
                },10);
            }
        }else{
            eachDegree = (sevenBranch - fiveBranch)/(Math.abs(-66) + Math.abs(sevenDegree)); //每一角度占的刻度
            nowDegree = (nIndex-fiveBranch)/eachDegree - 66;
            if(fiveDegree >= nowDegree) {
                clearInterval(t2);
            }
        }
        rotateFn(fiveDegree);
    };
    function move3(nIndex){

        sevenDegree = sevenDegree + 1;
        eachDegree = (endBranch - sevenBranch)/(endDegree - 66); //每一角度占的刻度
        nowDegree = (nIndex - sevenBranch)/eachDegree + 66;
        if(sevenDegree >= nowDegree) {
            clearInterval(t3);
        }
        rotateFn(sevenDegree);
    };
    function rotateFn(degree) {
        $('.pointer').css("-webkit-transform","rotate(" + (degree) + "deg)")
        $(".pointer").css("-o-transform","rotate(" + (degree) + "deg)");
        $(".pointer").css("-moz-transform","rotate(" + (degree) + "deg)");
        $(".pointer").css("-ms-transform","rotate(" + (degree) + "deg)");
    }

}
/**
 * 判断是否安装flash插件
 * @returns {{f: number, v: number}}
 */
function flashChecker() {
    var hasFlash = 0; //是否安装了flash
    var flashVersion = 0; //flash版本
    if (document.all) {
        var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
        if (swf) {
            hasFlash = 1;
            VSwf = swf.GetVariable("$version");
            flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
        }
    } else {
        if (navigator.plugins && navigator.plugins.length > 0) {
            var swf = navigator.plugins["Shockwave Flash"];
            if (swf) {
                hasFlash = 1;
                var words = swf.description.split(" ");
                for (var i = 0; i < words.length; ++i) {
                    if (isNaN(parseInt(words[i]))) continue;
                    flashVersion = parseInt(words[i]);
                }
            }
        }
    }
    return { f: hasFlash, v: flashVersion };
}




